package com.chartboost.sdk.Libraries;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ImageView;
import com.chartboost.sdk.Chartboost;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;

public class e
{
  private static e a = null;
  private d b = new d(Chartboost.sharedChartboost().getContext());
  private a c = new a();

  public static e a()
  {
    try
    {
      if (a == null)
        a = new e();
      e locale = a;
      return locale;
    }
    finally
    {
    }
  }

  private static a b(ImageView paramImageView)
  {
    if (paramImageView != null)
    {
      Drawable localDrawable = paramImageView.getDrawable();
      if ((localDrawable instanceof c))
        return ((c)localDrawable).a();
    }
    return null;
  }

  protected a.a a(String paramString)
    throws IOException
  {
    File localFile = this.b.a(paramString + ".png");
    if (!localFile.exists())
      return null;
    BufferedInputStream localBufferedInputStream = new BufferedInputStream(new FileInputStream(localFile));
    long l = localFile.length();
    if (l > 2147483647L)
      throw new IOException("Cannot read files larger than 2147483647 bytes");
    int i = (int)l;
    byte[] arrayOfByte = new byte[i];
    localBufferedInputStream.read(arrayOfByte, 0, i);
    localBufferedInputStream.close();
    BitmapFactory.Options localOptions1 = new BitmapFactory.Options();
    localOptions1.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(arrayOfByte, 0, arrayOfByte.length, localOptions1);
    BitmapFactory.Options localOptions2 = new BitmapFactory.Options();
    localOptions2.inJustDecodeBounds = false;
    localOptions2.inDither = false;
    localOptions2.inPurgeable = true;
    localOptions2.inInputShareable = true;
    localOptions2.inTempStorage = new byte[32768];
    localOptions2.inSampleSize = 1;
    while (true)
    {
      int j = localOptions2.inSampleSize;
      Object localObject = null;
      if (j >= 64)
        return new a.a((Bitmap)localObject, localOptions2.inSampleSize);
      try
      {
        Bitmap localBitmap = BitmapFactory.decodeByteArray(arrayOfByte, 0, arrayOfByte.length, localOptions2);
        localObject = localBitmap;
      }
      catch (OutOfMemoryError localOutOfMemoryError)
      {
        localOptions2.inSampleSize = (2 * localOptions2.inSampleSize);
      }
      catch (Exception localException)
      {
      }
    }
    return null;
  }

  public void a(String paramString1, String paramString2, b paramb, ImageView paramImageView, Bundle paramBundle)
  {
    boolean bool1;
    if (paramBundle != null)
      bool1 = paramBundle.getBoolean("paramNoMemoryCache");
    while (true)
    {
      a.a locala = null;
      if (!bool1);
      try
      {
        locala = this.c.a(paramString2);
        if (locala == null)
        {
          locala = a(paramString2);
          if (locala != null)
            if (!bool1)
              break label120;
        }
        label120: for (boolean bool2 = false; ; bool2 = true)
        {
          locala.a(bool2);
          if (!bool1)
            this.c.a(paramString2, locala);
          if (locala == null)
            break label136;
          if (paramImageView != null)
            paramImageView.setImageBitmap(locala.b());
          if (paramb != null)
            paramb.a(locala, paramBundle);
          return;
          bool1 = false;
          break;
        }
      }
      catch (Exception localException)
      {
        while (true)
          localException.printStackTrace();
        label136: new a(paramImageView, paramb, paramString2, paramBundle).execute(new String[] { paramString1 });
      }
    }
  }

  // ERROR //
  protected boolean a(String paramString, e parame)
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 34	com/chartboost/sdk/Libraries/e:b	Lcom/chartboost/sdk/Libraries/e$d;
    //   4: new 65	java/lang/StringBuilder
    //   7: dup
    //   8: aload_1
    //   9: invokestatic 71	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   12: invokespecial 74	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   15: ldc 76
    //   17: invokevirtual 80	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   20: invokevirtual 84	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   23: invokevirtual 87	com/chartboost/sdk/Libraries/e$d:a	(Ljava/lang/String;)Ljava/io/File;
    //   26: astore_3
    //   27: new 200	java/io/FileOutputStream
    //   30: dup
    //   31: aload_3
    //   32: invokespecial 201	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   35: astore 4
    //   37: sipush 4096
    //   40: newarray byte
    //   42: astore 10
    //   44: aload_2
    //   45: aload 10
    //   47: invokevirtual 206	com/chartboost/sdk/Libraries/e$e:read	([B)I
    //   50: istore 11
    //   52: iload 11
    //   54: iconst_m1
    //   55: if_icmpne +19 -> 74
    //   58: aload 4
    //   60: ifnull +8 -> 68
    //   63: aload 4
    //   65: invokevirtual 207	java/io/FileOutputStream:close	()V
    //   68: iconst_1
    //   69: istore 8
    //   71: iload 8
    //   73: ireturn
    //   74: aload 4
    //   76: aload 10
    //   78: iconst_0
    //   79: iload 11
    //   81: invokevirtual 211	java/io/FileOutputStream:write	([BII)V
    //   84: goto -40 -> 44
    //   87: astore 7
    //   89: iconst_0
    //   90: istore 8
    //   92: aload 4
    //   94: ifnull -23 -> 71
    //   97: aload 4
    //   99: invokevirtual 207	java/io/FileOutputStream:close	()V
    //   102: iconst_0
    //   103: ireturn
    //   104: astore 9
    //   106: iconst_0
    //   107: ireturn
    //   108: astore 5
    //   110: aconst_null
    //   111: astore 4
    //   113: aload 4
    //   115: ifnull +8 -> 123
    //   118: aload 4
    //   120: invokevirtual 207	java/io/FileOutputStream:close	()V
    //   123: aload 5
    //   125: athrow
    //   126: astore 12
    //   128: goto -60 -> 68
    //   131: astore 6
    //   133: goto -10 -> 123
    //   136: astore 5
    //   138: goto -25 -> 113
    //   141: astore 13
    //   143: aconst_null
    //   144: astore 4
    //   146: goto -57 -> 89
    //
    // Exception table:
    //   from	to	target	type
    //   37	44	87	java/lang/Exception
    //   44	52	87	java/lang/Exception
    //   74	84	87	java/lang/Exception
    //   97	102	104	java/lang/Exception
    //   27	37	108	finally
    //   63	68	126	java/lang/Exception
    //   118	123	131	java/lang/Exception
    //   37	44	136	finally
    //   44	52	136	finally
    //   74	84	136	finally
    //   27	37	141	java/lang/Exception
  }

  public void b()
  {
    this.b.a();
    this.c.a();
  }

  class a extends AsyncTask<String, Void, a.a>
  {
    private String b;
    private final WeakReference<ImageView> c;
    private e.b d;
    private String e;
    private Bundle f;

    public a(ImageView paramb, e.b paramString, String paramBundle, Bundle arg5)
    {
      this.c = new WeakReference(paramb);
      e.c localc = new e.c(this);
      if (paramb != null)
        paramb.setImageDrawable(localc);
      this.e = paramBundle;
      this.d = paramString;
      Object localObject;
      this.f = localObject;
    }

    // ERROR //
    protected a.a a(String[] paramArrayOfString)
    {
      // Byte code:
      //   0: aconst_null
      //   1: astore_2
      //   2: aload_0
      //   3: aload_1
      //   4: iconst_0
      //   5: aaload
      //   6: putfield 57	com/chartboost/sdk/Libraries/e$a:b	Ljava/lang/String;
      //   9: aload_0
      //   10: getfield 48	com/chartboost/sdk/Libraries/e$a:f	Landroid/os/Bundle;
      //   13: ifnull +61 -> 74
      //   16: aload_0
      //   17: getfield 48	com/chartboost/sdk/Libraries/e$a:f	Landroid/os/Bundle;
      //   20: ldc 59
      //   22: invokevirtual 65	android/os/Bundle:getBoolean	(Ljava/lang/String;)Z
      //   25: istore_3
      //   26: aload_0
      //   27: getfield 21	com/chartboost/sdk/Libraries/e$a:a	Lcom/chartboost/sdk/Libraries/e;
      //   30: aload_0
      //   31: getfield 44	com/chartboost/sdk/Libraries/e$a:e	Ljava/lang/String;
      //   34: invokevirtual 70	com/chartboost/sdk/Libraries/e:a	(Ljava/lang/String;)Lcom/chartboost/sdk/Libraries/a$a;
      //   37: astore 27
      //   39: aload 27
      //   41: astore 5
      //   43: aload 5
      //   45: ifnull +50 -> 95
      //   48: iload_3
      //   49: ifeq +30 -> 79
      //   52: iconst_0
      //   53: istore 28
      //   55: aload 5
      //   57: iload 28
      //   59: invokevirtual 75	com/chartboost/sdk/Libraries/a$a:a	(Z)V
      //   62: aload 5
      //   64: astore 6
      //   66: aload 6
      //   68: ifnull +34 -> 102
      //   71: aload 6
      //   73: areturn
      //   74: iconst_0
      //   75: istore_3
      //   76: goto -50 -> 26
      //   79: iconst_1
      //   80: istore 28
      //   82: goto -27 -> 55
      //   85: astore 4
      //   87: aconst_null
      //   88: astore 5
      //   90: aload 4
      //   92: invokevirtual 78	java/lang/Exception:printStackTrace	()V
      //   95: aload 5
      //   97: astore 6
      //   99: goto -33 -> 66
      //   102: invokestatic 83	com/chartboost/sdk/impl/j:b	()Lorg/apache/http/client/HttpClient;
      //   105: astore 7
      //   107: new 85	org/apache/http/client/methods/HttpGet
      //   110: dup
      //   111: aload_0
      //   112: getfield 57	com/chartboost/sdk/Libraries/e$a:b	Ljava/lang/String;
      //   115: invokespecial 88	org/apache/http/client/methods/HttpGet:<init>	(Ljava/lang/String;)V
      //   118: astore 8
      //   120: aload 7
      //   122: aload 8
      //   124: invokeinterface 94 2 0
      //   129: astore 18
      //   131: aload 18
      //   133: invokeinterface 100 1 0
      //   138: invokeinterface 106 1 0
      //   143: istore 19
      //   145: iload 19
      //   147: sipush 200
      //   150: if_icmpeq +40 -> 190
      //   153: ldc 108
      //   155: new 110	java/lang/StringBuilder
      //   158: dup
      //   159: ldc 112
      //   161: invokespecial 113	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   164: iload 19
      //   166: invokevirtual 117	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
      //   169: ldc 119
      //   171: invokevirtual 122	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   174: aload_0
      //   175: getfield 57	com/chartboost/sdk/Libraries/e$a:b	Ljava/lang/String;
      //   178: invokevirtual 122	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   181: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   184: invokestatic 132	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;)I
      //   187: pop
      //   188: aconst_null
      //   189: areturn
      //   190: aload 18
      //   192: invokeinterface 136 1 0
      //   197: astore 21
      //   199: aload 21
      //   201: ifnull +301 -> 502
      //   204: aload 21
      //   206: invokeinterface 142 1 0
      //   211: astore_2
      //   212: aload_0
      //   213: getfield 21	com/chartboost/sdk/Libraries/e$a:a	Lcom/chartboost/sdk/Libraries/e;
      //   216: aload_0
      //   217: getfield 44	com/chartboost/sdk/Libraries/e$a:e	Ljava/lang/String;
      //   220: new 144	com/chartboost/sdk/Libraries/e$e
      //   223: dup
      //   224: aload_2
      //   225: invokespecial 147	com/chartboost/sdk/Libraries/e$e:<init>	(Ljava/io/InputStream;)V
      //   228: invokevirtual 150	com/chartboost/sdk/Libraries/e:a	(Ljava/lang/String;Lcom/chartboost/sdk/Libraries/e$e;)Z
      //   231: pop
      //   232: aload_0
      //   233: getfield 21	com/chartboost/sdk/Libraries/e$a:a	Lcom/chartboost/sdk/Libraries/e;
      //   236: aload_0
      //   237: getfield 44	com/chartboost/sdk/Libraries/e$a:e	Ljava/lang/String;
      //   240: invokevirtual 70	com/chartboost/sdk/Libraries/e:a	(Ljava/lang/String;)Lcom/chartboost/sdk/Libraries/a$a;
      //   243: astore 6
      //   245: aload 6
      //   247: ifnull +248 -> 495
      //   250: iconst_0
      //   251: istore 26
      //   253: iload_3
      //   254: ifeq +52 -> 306
      //   257: aload 6
      //   259: iload 26
      //   261: invokevirtual 75	com/chartboost/sdk/Libraries/a$a:a	(Z)V
      //   264: iload_3
      //   265: ifne +230 -> 495
      //   268: aload_0
      //   269: getfield 21	com/chartboost/sdk/Libraries/e$a:a	Lcom/chartboost/sdk/Libraries/e;
      //   272: invokestatic 153	com/chartboost/sdk/Libraries/e:a	(Lcom/chartboost/sdk/Libraries/e;)Lcom/chartboost/sdk/Libraries/a;
      //   275: aload_0
      //   276: getfield 44	com/chartboost/sdk/Libraries/e$a:e	Ljava/lang/String;
      //   279: aload 6
      //   281: invokevirtual 158	com/chartboost/sdk/Libraries/a:a	(Ljava/lang/String;Lcom/chartboost/sdk/Libraries/a$a;)V
      //   284: aload 6
      //   286: astore 11
      //   288: aload_2
      //   289: ifnull +7 -> 296
      //   292: aload_2
      //   293: invokevirtual 163	java/io/InputStream:close	()V
      //   296: aload 21
      //   298: invokeinterface 166 1 0
      //   303: aload 11
      //   305: areturn
      //   306: iconst_1
      //   307: istore 26
      //   309: goto -52 -> 257
      //   312: astore 24
      //   314: aload 24
      //   316: invokevirtual 78	java/lang/Exception:printStackTrace	()V
      //   319: aload 6
      //   321: astore 11
      //   323: goto -35 -> 288
      //   326: astore 22
      //   328: aload_2
      //   329: ifnull +7 -> 336
      //   332: aload_2
      //   333: invokevirtual 163	java/io/InputStream:close	()V
      //   336: aload 21
      //   338: invokeinterface 166 1 0
      //   343: aload 22
      //   345: athrow
      //   346: astore 15
      //   348: aload 15
      //   350: astore 16
      //   352: aload 6
      //   354: astore 11
      //   356: aload 8
      //   358: invokevirtual 169	org/apache/http/client/methods/HttpGet:abort	()V
      //   361: ldc 171
      //   363: new 110	java/lang/StringBuilder
      //   366: dup
      //   367: ldc 173
      //   369: invokespecial 113	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   372: aload_0
      //   373: getfield 57	com/chartboost/sdk/Libraries/e$a:b	Ljava/lang/String;
      //   376: invokevirtual 122	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   379: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   382: aload 16
      //   384: invokestatic 176	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
      //   387: pop
      //   388: goto -85 -> 303
      //   391: astore 13
      //   393: aload 6
      //   395: astore 11
      //   397: aload 8
      //   399: invokevirtual 169	org/apache/http/client/methods/HttpGet:abort	()V
      //   402: ldc 171
      //   404: new 110	java/lang/StringBuilder
      //   407: dup
      //   408: ldc 178
      //   410: invokespecial 113	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   413: aload_0
      //   414: getfield 57	com/chartboost/sdk/Libraries/e$a:b	Ljava/lang/String;
      //   417: invokevirtual 122	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   420: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   423: invokestatic 132	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;)I
      //   426: pop
      //   427: goto -124 -> 303
      //   430: astore 9
      //   432: aload 9
      //   434: astore 10
      //   436: aload 6
      //   438: astore 11
      //   440: aload 8
      //   442: invokevirtual 169	org/apache/http/client/methods/HttpGet:abort	()V
      //   445: ldc 171
      //   447: new 110	java/lang/StringBuilder
      //   450: dup
      //   451: ldc 180
      //   453: invokespecial 113	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
      //   456: aload_0
      //   457: getfield 57	com/chartboost/sdk/Libraries/e$a:b	Ljava/lang/String;
      //   460: invokevirtual 122	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
      //   463: invokevirtual 126	java/lang/StringBuilder:toString	()Ljava/lang/String;
      //   466: aload 10
      //   468: invokestatic 176	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
      //   471: pop
      //   472: goto -169 -> 303
      //   475: astore 10
      //   477: goto -37 -> 440
      //   480: astore 25
      //   482: goto -85 -> 397
      //   485: astore 16
      //   487: goto -131 -> 356
      //   490: astore 4
      //   492: goto -402 -> 90
      //   495: aload 6
      //   497: astore 11
      //   499: goto -211 -> 288
      //   502: aload 6
      //   504: astore 11
      //   506: goto -203 -> 303
      //
      // Exception table:
      //   from	to	target	type
      //   26	39	85	java/lang/Exception
      //   232	245	312	java/lang/Exception
      //   257	264	312	java/lang/Exception
      //   268	284	312	java/lang/Exception
      //   204	232	326	finally
      //   232	245	326	finally
      //   257	264	326	finally
      //   268	284	326	finally
      //   314	319	326	finally
      //   120	145	346	java/io/IOException
      //   153	188	346	java/io/IOException
      //   190	199	346	java/io/IOException
      //   332	336	346	java/io/IOException
      //   336	346	346	java/io/IOException
      //   120	145	391	java/lang/IllegalStateException
      //   153	188	391	java/lang/IllegalStateException
      //   190	199	391	java/lang/IllegalStateException
      //   332	336	391	java/lang/IllegalStateException
      //   336	346	391	java/lang/IllegalStateException
      //   120	145	430	java/lang/Exception
      //   153	188	430	java/lang/Exception
      //   190	199	430	java/lang/Exception
      //   332	336	430	java/lang/Exception
      //   336	346	430	java/lang/Exception
      //   292	296	475	java/lang/Exception
      //   296	303	475	java/lang/Exception
      //   292	296	480	java/lang/IllegalStateException
      //   296	303	480	java/lang/IllegalStateException
      //   292	296	485	java/io/IOException
      //   296	303	485	java/io/IOException
      //   55	62	490	java/lang/Exception
    }

    protected void a(a.a parama)
    {
      if (isCancelled());
      while (true)
      {
        return;
        if (parama != null);
        try
        {
          e.a(e.this).a(this.e, parama);
          if (this.c != null)
          {
            ImageView localImageView = (ImageView)this.c.get();
            if (this == e.a(localImageView))
              localImageView.setImageBitmap(parama.b());
          }
          if (this.d == null)
            continue;
          this.d.a(parama, this.f);
          return;
        }
        catch (Exception localException)
        {
          while (true)
            localException.printStackTrace();
        }
      }
    }
  }

  public static abstract interface b
  {
    public abstract void a(a.a parama, Bundle paramBundle);
  }

  static class c extends BitmapDrawable
  {
    private final WeakReference<e.a> a;

    public c(e.a parama)
    {
      this.a = new WeakReference(parama);
    }

    public e.a a()
    {
      return (e.a)this.a.get();
    }
  }

  private static class d
  {
    private File a = null;

    public d(Context paramContext)
    {
      try
      {
        if (paramContext.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == 0);
        for (int i = 1; ; i = 0)
        {
          if ((i != 0) && (Environment.getExternalStorageState().equals("mounted")))
            this.a = paramContext.getExternalFilesDir("cache");
          if ((this.a != null) && (!this.a.exists()))
            this.a.mkdirs();
          if (this.a == null)
          {
            this.a = paramContext.getCacheDir();
            if (!this.a.exists())
              this.a.mkdirs();
          }
          return;
        }
      }
      catch (Exception localException)
      {
        while (true)
          this.a = null;
      }
    }

    public File a(String paramString)
    {
      return new File(this.a, paramString);
    }

    public void a()
    {
      try
      {
        File[] arrayOfFile = this.a.listFiles();
        if (arrayOfFile == null)
          return;
        int i = arrayOfFile.length;
        for (int j = 0; j < i; j++)
          arrayOfFile[j].delete();
      }
      catch (Exception localException)
      {
      }
    }
  }

  static class e extends FilterInputStream
  {
    public e(InputStream paramInputStream)
    {
      super();
    }

    public long skip(long paramLong)
      throws IOException
    {
      long l2;
      for (long l1 = 0L; ; l1 = l2 + l1)
      {
        if (l1 >= paramLong);
        do
        {
          return l1;
          l2 = this.in.skip(paramLong - l1);
          if (l2 != 0L)
            break;
        }
        while (read() < 0);
        l2 = 1L;
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.chartboost.sdk.Libraries.e
 * JD-Core Version:    0.6.2
 */